package com.mdp.sms.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mdp.core.utils.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Service;
import com.mdp.core.service.BaseService;
import static com.mdp.core.utils.BaseUtils.*;
import com.mdp.core.entity.Tips;
import com.mdp.core.err.BizException;

import com.mdp.sms.entity.SmsFlow;
import com.mdp.sms.mapper.SmsFlowMapper;
import org.springframework.util.StringUtils;

/**
 * @author maimeng-mdp code-gen
 * @since 2024-3-6
 */
@Service
public class SmsFlowService extends BaseService<SmsFlowMapper,SmsFlow> {
	static Logger logger =LoggerFactory.getLogger(SmsFlowService.class);

	/**
	 * 自定义查询，支持多表关联
	 * @param page 分页条件
	 * @param ew 一定要，并且必须加@Param("ew")注解
	 * @param ext 如果xml中需要根据某些值进行特殊处理，可以通过这个进行传递，非必须，注解也可以不加
	 * @return
	 */
	public List<Map<String,Object>> selectListMapByWhere(IPage page, QueryWrapper ew, Map<String,Object> ext){
		return baseMapper.selectListMapByWhere(page,ew,ext);
	}


	/** 请在此类添加自定义函数 */
	/**
	 * 批量创建创建流水
	 */
	public SmsFlow batchCreateSmsFlow(String smsTempateId, String content, String smsSign, String smsTemplateParams,
									  String smsTemplateText, String sendBranchId, String shopId, String locationId, String mobile, String nationcode, BigDecimal number, String sendUserid,
									  String extendNo, String sendStatus, String errmsg, String replyStatus, String replyEndDateStr) {
		Date createDate= DateUtils.getNowDate();
		Date replyEndDate=null;
		Calendar calendar=Calendar.getInstance();
		if(StringUtils.hasText(replyEndDateStr)&&"1".equals(replyStatus)) {
			calendar.add(Calendar.DAY_OF_YEAR , Integer.valueOf(replyEndDateStr));
			replyEndDate=calendar.getTime();
		}
		SmsFlow customerInsertSmsFlowObject=new SmsFlow();
		customerInsertSmsFlowObject.setId(this.createKey("id"));
		customerInsertSmsFlowObject.setSmsTempateId(smsTempateId);
		customerInsertSmsFlowObject.setContent(content);
		customerInsertSmsFlowObject.setCreateDate(createDate);
		customerInsertSmsFlowObject.setSmsSign(smsSign);
		customerInsertSmsFlowObject.setSmsTemplateParams(smsTemplateParams);
		customerInsertSmsFlowObject.setSmsTemplateText(smsTemplateText);
		customerInsertSmsFlowObject.setSendBranchId(sendBranchId);
		customerInsertSmsFlowObject.setSendShopId(shopId);
		customerInsertSmsFlowObject.setSendLocationId(locationId);
		customerInsertSmsFlowObject.setSendTime(createDate);
		customerInsertSmsFlowObject.setNumber(number);
		customerInsertSmsFlowObject.setSendUserid(sendUserid);
		customerInsertSmsFlowObject.setSendStatus(sendStatus);
		customerInsertSmsFlowObject.setSendDetail(errmsg);;
		customerInsertSmsFlowObject.setMobile(mobile);
		customerInsertSmsFlowObject.setNationcode(nationcode);
		customerInsertSmsFlowObject.setExtendNo(extendNo);
		customerInsertSmsFlowObject.setReplyStatus(replyStatus);
		customerInsertSmsFlowObject.setReplyEndDate(replyEndDate);
		return customerInsertSmsFlowObject;
	}
}

